﻿@using Huirui.Cavan.Domain.MainBoundedContext.PurchaseModule
@model Huirui.Cavan.Presentation.ViewModel.PurchaseModule.IUnPayViewModel
@{Layout = null;}
@using (Html.BeginForm(ActionConst.ADD, ControllerConst.UNPAY))
{
    <div class="tool_bar">
        <input id="supplierini_save" type="submit" style="display: none;" />
        <input id="supplierini_reset" type="reset" style="display: none" />
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'"
            onclick="javascript:$('#supplierini_save').click()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-copy'">复制选中项</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-undo'"
            onclick="javascript:$('#supplierini_reset').click()">重置</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-collapse'"
            onclick="toggleHeard()">折叠/展开</a>
    </div>
    <table class="form_heard">
        <tr>
            <td class="c100">
                <label>往来类型:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.Type, typeof(PurchaseIdentifier.UnPayType), new { id = "supplierIniType", @class = "easyui-combobox", @required = true })
            </td>
            <td class="c100">
                <label>余额日期:</label>
            </td>
            <td class="c164">
                @Html.TextBoxFor(m => m.Item.CreateDate, new { id = "supplierInitialDate", @class = "Wdate", onfocus = "WdatePicker()" })
            </td>
            <td class="c160">
                <label>供应商名称:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Supplier.Name, new { id = "supplierNameForSupplierIni" })
                @Html.HiddenFor(m => m.Item.Supplier.Id, new { id = "supplierCodeForSupplierIni" })
            </td>

        </tr>
        <tr>
            <td class="c100">
                <label>金额:</label>
            </td>
            <td class="c164">
                @Html.TextBoxFor(m => m.Item.Cost, new { id = "amountForSupplierIni" })
            </td>
            <td class="c100">
                <label>币别:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Currency, new { id = "currencyForSupplierIni" })
            </td>
            <td class="c100">
                <label>汇率:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.CurrencyRate, new { id = "currencyRateForSupplierIni" })
            </td>
        </tr>
    </table>
}
<table id="supplierIni_dg">
    <thead>
        <tr>
            <th field="ck" checkbox="true"></th>
            <th field="UnPayType" width="80">往来类型
            </th>
            <th field="CreateDate" width="80">初始日期
            </th>
            <th field="SupplierName" width="80">供应商名称
            </th>
            <th field="Amount" width="80">金额
            </th>
            <th field="Currency" width="80">币别
            </th>
            <th field="CurrencyRate" width="80">汇率
            </th>
        </tr>
    </thead>
</table>
<div id="supplierInitb">
    <a href="#" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="javascript:alert('引出')">引出</a>
</div>
@{ Html.RenderAction(ActionConst.SEARCH, ControllerConst.SUPPLIER, new { purpose = "ForSupplierIni" }); }
<script type="text/javascript">
    $(function () {
        $("form[action^='/unpay/add']").submit(function () {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (data) {
                    if (data.IsSuccess) {
                        loadData();
                    }
                },
                error: function () {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $("select#supplierIniType").bind("change", function () {
            loadData();
        });

        function loadData() {
            $('#supplierIni_dg').datagrid('loadData', { total: 0, rows: [] });
            $.ajax({
                url: "/unpay/listbytype?type=" + $("select#supplierIniType").val(),
                type: 'Post',
                success: function (result) {
                    if (result.total > 0) {
                        $('#supplierIni_dg').datagrid({
                            data: result
                        });
                    }
                },
                error: function () {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        }

        $('#supplierIni_dg').datagrid({
            class: 'easyui-datagrid',
            title: "应付初始余额",
            idField: 'ID',
            fitColumns: true,
            toolbar: '#supplierInitb',
            onClickRow: function (rowIndex, rowData) {
                $("#supplierNameForSupplierIni").val(rowData.SupplierName);
                $("#supplierCodeForSupplierIni").val(rowData.SupplierCode);
                $("select#SupplierIniType").attr('value', rowData.UnPayType);
                $("#amountForSupplierIni").val(rowData.Amount);
                $("#currencyForSupplierIni").val(rowData.Currency);
                $("#currencyRateForSupplierIni").val(rowData.CurrencyRate);
                $("input").css('color', '#333333');
            }
        });

        $("#supplierNameForSupplierIni").bind("click", function () {
            InitSelectSupplier('suppliersForSupplierIni');
            openWindow("selectSupplierWindowForSupplierIni");
        });

        $("#searchSupplierForSupplierIni").submit(function () {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    if (result.total > 0) {
                        $('#suppliersForSupplierIni').datagrid({
                            data: result,
                            checkOnSelect: true,
                            selectOnCheck: true
                        });
                    }
                },
                error: function () {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $("#doSelectSupplierForSupplierIni").bind("click", function () {
            var currentRow = $('#suppliersForSupplierIni').datagrid('getSelected');
            $("#supplierCodeForSupplierIni").val(currentRow.Id);
            $("#supplierNameForSupplierIni").val(currentRow.Name);
            closeWindow("selectSupplierWindowForSupplierIni");
        });
    });
</script>

